package com.wuyi.tea.controller.user;

import com.wuyi.tea.domain.dto.TradeFormDTO;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.service.UserService;
import com.wuyi.tea.util.LocalStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "交易模块")
@RestController
@RequestMapping("/user")
public class TradeController {

    @Resource
    private UserService userService;

    @ApiOperation("充值金额")
    @PostMapping("/topUp")
    public R topUp(@RequestBody TradeFormDTO tradeFormDTO){

        log.info("id为{}的用户正在充值 {}茶币", LocalStorageUtil.get(),tradeFormDTO.getTopUp());
        userService.topUp(tradeFormDTO);
        return R.success(tradeFormDTO.getTopUp()+" 茶币已到账",null);
    }


    @ApiOperation("支付功能")
    @PostMapping("/pay")
    public R pay(@RequestBody TradeFormDTO tradeFormDTO){

        log.info("id为{}的用户正在使用支付功能,支付信息:\n{}",LocalStorageUtil.get(),tradeFormDTO);
        userService.pay(tradeFormDTO);
        return R.success("已支付 "+tradeFormDTO.getPayMoney()+" 茶币",null);
    }


}
